﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>preview1</title>
<script language="JavaScript">
Function.prototype.bind = function () {
	var _t = this, args = Array.prototype.slice.apply(arguments, [0]), o = args.shift();
	return function () {
		_t.apply(o, args.concat(Array.prototype.slice.apply(arguments, [0])));	
	};
};
function $(id) { 
	if (typeof id == 'string') return document.getElementById(id);
	return id;
}
var AjaxUpdate = function (url, cnt) {
	this.__init(url, cnt);	
}
AjaxUpdate.ScriptFragment = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
AjaxUpdate.prototype = {
	__init: function (url, cnt) {
		var http = this._getHttp();
		if (!http) return;
		this.http = http;
		this.cnt = $(cnt);
		http.open('get', url, true);
		http.onreadystatechange = this._onStateChange.bind(this);		
		http.send(null);
	},
	_getHttp: function () {
		var trys = ['new XMLHttpRequest()', 'new ActiveXObject("Msxml2.XMLHTTP")', 'new ActiveXObject("Microsoft.XMLHTTP")'];
 		for (var i = 0; i < trys.length; i ++) {try {return eval(trys[i]) } catch(e) {}	}
 		return false;		
	},
	_onStateChange: function () {
		var http = this.http;
		if (http.readyState == 4) {
    			//if (http.status == 200) {
    				this._update(http.responseText);
    			//}	
    		}	
	},
	_update: function (content) {
		this.cnt.innerHTML = this._trimScripts(content);
		this._evalScripts(content);
	},
	_trimScripts: function (content) {
		return content.replace(new RegExp(AjaxUpdate.ScriptFragment, 'img'), '');
	},
	_getScripts: function (content) {
		var matchAll = new RegExp(AjaxUpdate.ScriptFragment, 'img');
    		var matchOne = new RegExp(AjaxUpdate.ScriptFragment, 'im');
    		var ret = [];
    		scripts = content.match(matchAll) || [];
    		for (var i = 0; i < scripts.length; i++) {
    			ret.push((scripts[i].match(matchOne) || ['', ''])[1]);
    		}
    		return ret;
	},
	_evalScripts: function (content) {
		var scripts = this._getScripts(content);
		for (var i = 0; i < scripts.length; i++) {
			eval(scripts[i]);	
		}	
	}
};
function update(url, cnt) {
	new AjaxUpdate(url, cnt);	
}
window.onload = function() {
setTimeout(function () {update('load1.html', 'contentCnt')}, 1000);
}
</script>
<style>
.fullWidth{width:220px;height:540px;overflow:hidden}
</style>
</head>
<body>
<div id="contentCnt" class="fullWidth"><img src="bg1.png"/></div>
</body>
</html>